﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DataLayer
{
    public class dluserproduct
    {
        public DataSet UserproductsList(int userid)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = @"SELECT DISTINCT Product.ProductId, Product.Name
FROM            Product INNER JOIN
                         Sprints ON Product.ProductId = Sprints.ProductID INNER JOIN
                         UserStory ON Sprints.SprintId = UserStory.SprintID INNER JOIN
                         Tasks ON UserStory.UserStoryId = Tasks.UserStoryId";
//Removed : "WHERE        (Tasks.UserId = '"+userid+"')";

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            SqlDataAdapter myadapter = new SqlDataAdapter(querylogin);
            DataSet mydataset = new DataSet();

            myadapter.Fill(mydataset);

            return mydataset;
        }
        public DataSet SprintList(int prodid)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = @"SELECT DISTINCT Sprints.SprintId, Sprints.Titel
FROM         Sprints 
WHERE        (Sprints.ProductID = '" + prodid + "')";

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            SqlDataAdapter myadapter = new SqlDataAdapter(querylogin);
            DataSet mydataset = new DataSet();

            myadapter.Fill(mydataset);

            return mydataset;
        }
        public DataSet USList(int sprintid)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = @"SELECT DISTINCT UserStory.UserStoryId, UserStory.Titel
FROM         UserStory
WHERE        (UserStory.SprintID = '" + sprintid + "')";

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            SqlDataAdapter myadapter = new SqlDataAdapter(querylogin);
            DataSet mydataset = new DataSet();

            myadapter.Fill(mydataset);

            return mydataset;


        }
        public DataSet TaskList(int usid)
        {
            string connStr = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
            string querystring = @"SELECT DISTINCT Tasks.TaskId, Tasks.Titel
FROM          Tasks
WHERE        (Tasks.UserStoryId = '" + usid + "')";

            SqlConnection connection = new SqlConnection(connStr);
            SqlCommand querylogin = new SqlCommand(querystring, connection);

            SqlDataAdapter myadapter = new SqlDataAdapter(querylogin);
            DataSet mydataset = new DataSet();

            myadapter.Fill(mydataset);

            return mydataset;
        }
    }
}
